Skip to content

fix: strip legacy judge messages on direct judge_config() path#174

Merged
jsonbailey merged 1 commit intomainfrom
jb/fix-judge-config-strip
May 7, 2026
Merged

fix: strip legacy judge messages on direct judge_config() path#174
jsonbailey merged 1 commit intomainfrom
jb/fix-judge-config-strip

Conversation

@jsonbailey
Copy link
Copy Markdown
Contributor

@jsonbailey jsonbailey commented May 7, 2026

Summary

Follow-up bug fix for the judge string-input PR (#165), which has already merged.

LDAIClient exposes two ways to get a judge AI config:

  1. create_judge() -> _create_judge_instance() -> _judge_config() -> __evaluate()
  2. judge_config() -> _judge_config() -> __evaluate()

_judge_config() calls _strip_legacy_judge_messages() on the messages returned by __evaluate() to remove legacy template messages whose content is {{message_history}} / {{response_to_evaluate}}. The strip pass relies on those literal markers being present in the rendered content.

Before this PR, _create_judge_instance() injected extended_variables = {..., 'message_history': '{{message_history}}', 'response_to_evaluate': '{{response_to_evaluate}}'} so the markers survived Mustache rendering. The direct judge_config() path passed user variables straight through to _judge_config(), so without the marker injection Mustache rendered the placeholders to empty strings and the strip pass found nothing matching. Legacy LDMessage(role='user', content='Evaluate: ') entries leaked into the returned config.

Fix

  • Move the reserved-variable warning and the marker injection from _create_judge_instance() into _judge_config() itself, so both code paths get correct behavior.
  • Simplify _create_judge_instance() to call self._judge_config(...) directly with the user's variables.
  • Add regression tests against LDAIClient.judge_config() covering: legacy messages get stripped from the returned config, user variables still interpolate, and reserved variables still produce warnings.

This mirrors the JS sibling fix in launchdarkly/js-core#1364.

Why a follow-up

The original PR (#165) added the strip helper and wired it into _judge_config(), but only _create_judge_instance() injected the markers needed for the helper to detect them. That PR has already merged, so this fix is a separate follow-up rather than an amendment.

Test plan

  • make test passes (server-ai, langchain, openai)
  • make lint passes (mypy, isort, pycodestyle)
  • New regression test exercises client.judge_config() against a config with legacy {{message_history}} / {{response_to_evaluate}} messages and asserts they are stripped from the returned config

Note

Low Risk
Low risk bug fix isolated to judge-config evaluation and warning behavior, with added regression tests to lock in legacy-message stripping and variable interpolation.

Overview
Ensures legacy judge template messages ({{message_history}}, {{response_to_evaluate}}) are stripped even when callers use the direct judge_config() API by moving reserved-variable placeholder injection (and associated warnings) into _judge_config().

Simplifies judge construction to pass user variables through unchanged, and adds regression tests verifying legacy-message stripping, normal variable interpolation, and warnings when callers attempt to set reserved variable names.

Reviewed by Cursor Bugbot for commit f62ae83. Bugbot is set up for automated code reviews on this repo. Configure here.

Move reserved-variable warnings and ``message_history``/
``response_to_evaluate`` marker injection from ``_create_judge_instance``
into ``_judge_config`` so both the direct ``judge_config()`` API and the
``create_judge()`` wrapper get correct legacy-message stripping.

Previously the markers were only injected by ``_create_judge_instance``,
so callers using ``judge_config()`` directly saw legacy
``{{message_history}}``/``{{response_to_evaluate}}`` placeholders
rendered to empty strings by Mustache before
``_strip_legacy_judge_messages`` ran, leaving the legacy messages intact
in the returned config.

Mirrors the JS sibling fix in launchdarkly/js-core#1364.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jsonbailey jsonbailey marked this pull request as ready for review May 7, 2026 16:30
@jsonbailey jsonbailey requested a review from a team as a code owner May 7, 2026 16:30
@jsonbailey jsonbailey merged commit b7db754 into main May 7, 2026
45 checks passed
@jsonbailey jsonbailey deleted the jb/fix-judge-config-strip branch May 7, 2026 16:39
@github-actions github-actions Bot mentioned this pull request May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants